package cn.iocoder.yudao.module.member.mq.consumer.user;

import cn.iocoder.yudao.module.member.mq.message.user.MemberUserCreateMessage;
import cn.iocoder.yudao.module.member.service.userpromotionrecords.UserPromotionRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class UserPromotionRecordsConsumer {

    @Resource
    private UserPromotionRecordsService userPromotionRecordsService;

    @Async // Spring Event 默认在 Producer 发送的线程，通过 @Async 实现异步
    @EventListener
    public void onMessage(MemberUserCreateMessage message) {
        log.info("[onMessage][消息内容({})]", message);
        userPromotionRecordsService.createUserPromotionRecords(message.getUserId(), message.getInviteCode());
    }

}
